<template>
  <view class="my-pets">
    <!-- 宠物列表 -->
    <view class="pet-list" v-if="pets.length">
      <view class="pet-card" v-for="(pet, index) in pets" :key="index" @click="viewPetDetail(pet._id)">
        <image class="pet-image" :src="pet.image || '/static/pet-placeholder.png'" mode="aspectFill" />
        <view class="pet-info">
          <text class="pet-name">{{pet.name}}</text>
          <text class="pet-species">{{pet.species}}</text>
          <text class="pet-age">{{pet.age}}岁</text>
        </view>
        <uni-icons type="right" size="16" color="#999" />
      </view>
    </view>

    <!-- 空状态 -->
    <view class="empty-state" v-else>
      <image src="/static/empty-pets.png" mode="aspectFit" />
      <text>还没有添加宠物哦</text>
    </view>

    <!-- 添加宠物按钮 -->
    <view class="add-btn" @click="addPet">
      <uni-icons type="plus" size="24" color="#fff" />
      <text>添加宠物</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      pets: []
    }
  },
  methods: {
    viewPetDetail(petId) {
      uni.navigateTo({
        url: '/pages/pet-detail/pet-detail?id=' + petId
      })
    },
    addPet() {
      uni.navigateTo({
        url: '/pages/add-pet/add-pet'
      })
    },
    async loadPets() {
      try {
        const res = await uniCloud.callFunction({
          name: 'getPets',
          data: {}
        })
        if (res.result.code === 200) {
          this.pets = res.result.data
        }
      } catch (error) {
        uni.showToast({
          title: '加载失败',
          icon: 'none'
        })
      }
    }
  },
  onShow() {
    this.loadPets()
  }
}
</script>

<style lang="scss">
.my-pets {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 120rpx;
}

.pet-list {
  padding: 20rpx;

  .pet-card {
    background: #fff;
    border-radius: 16rpx;
    padding: 20rpx;
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;

    .pet-image {
      width: 120rpx;
      height: 120rpx;
      border-radius: 60rpx;
      margin-right: 20rpx;
    }

    .pet-info {
      flex: 1;

      .pet-name {
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
        display: block;
      }

      .pet-species {
        font-size: 26rpx;
        color: #666;
        margin-top: 8rpx;
        display: block;
      }

      .pet-age {
        font-size: 24rpx;
        color: #999;
        margin-top: 4rpx;
        display: block;
      }
    }
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 0;

  image {
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 20rpx;
  }

  text {
    color: #999;
    font-size: 28rpx;
  }
}

.add-btn {
  position: fixed;
  bottom: 40rpx;
  left: 50%;
  transform: translateX(-50%);
  background: #5cb85c;
  color: #fff;
  padding: 20rpx 60rpx;
  border-radius: 40rpx;
  display: flex;
  align-items: center;
  gap: 10rpx;
  box-shadow: 0 4rpx 12rpx rgba(92, 184, 92, 0.3);

  text {
    font-size: 28rpx;
  }
}
</style> 